//
//  WYLoginController.m
//  CirclePush
//
//  Created by admin on 2018/4/13.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYLoginController.h"
#import "WYRegisterController.h"
#import "ZYMainController.h"
#import "WYForgetPasswordController.h"
@interface WYLoginController ()
@property (strong, nonatomic) IBOutlet UITextField *nameTextField;
@property (strong, nonatomic) IBOutlet UITextField *pwdTextField;

@end

@implementation WYLoginController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    // Do any additional setup after loading the view from its nib.
}
-(void)setupUI
{
    self.nameTextField.clearButtonMode =UITextFieldViewModeWhileEditing;
    self.nameTextField.leftView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"number"]];
    self.nameTextField.leftViewMode = UITextFieldViewModeAlways;
    self.pwdTextField.leftView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"password"]];
    self.pwdTextField.leftViewMode = UITextFieldViewModeAlways;
    
    [self.nameTextField setCornerRadius:5.0f];
    [self.pwdTextField setCornerRadius:5.0f];
    self.view.backgroundColor = [UIColor whiteColor];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)loginAction:(UIButton *)sender {
    if (!self.nameTextField.text.length) {
        [self toast:@"请输入用户名"];
    }
    if (!self.pwdTextField.text.length) {
        [self toast:@"请输入密码"];
    }
    WEAKSELF
    [WYHttpServer masterLogin:self.nameTextField.text Withpassword:self.pwdTextField.text SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        if (success) {
            [WYStoreModule storeToken:response[@"result"]];
            ZYMainController *TabBarVC = [[ZYMainController alloc]init];
            TabBarVC.tabBar.translucent = NO;
            [weakSelf presentViewController:TabBarVC animated:YES completion:nil];
        }else{
            [weakSelf toast:errorMessage];
        }
        
        
        
        
        
        
    }];
    
    
    
    
    
    
}
- (IBAction)registerAction:(id)sender {
    WYRegisterController *rvc = [[WYRegisterController alloc]init];
    [self.navigationController pushViewController:rvc animated:YES];
    
    
    
}


- (IBAction)forgetAction:(id)sender {
    WYForgetPasswordController *fpc = [[WYForgetPasswordController alloc]init];
    [self.navigationController pushViewController:fpc animated:YES];
    
    
}






@end
